<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const arr = ["red", "green", "blue"];
      // 数组的map方法
      const newArr = arr.map(function (ele, index) {
        console.log(ele);
        console.log(index);
        return ele + "颜色";
      });
      console.log(newArr);
      // 数组的join方法 把数组的元素拼接成一个字符串
      // 小括号为空则逗号分隔
      console.log(newArr.join()); // red颜色,green颜色,blue颜色
      // 小括号为" "则元素之间没有分割符
      console.log(newArr.join("")); // red颜色green颜色blue颜色
    </script>
  </body>
</html>
